package com.study.spark.scala.sql

import org.apache.spark.sql.SparkSession

/**
  * spark与mysql集成
  */
object MySQLDemo {

  def main(args: Array[String]): Unit = {

    val spark = SparkSession.builder()
      .master("local[2]")
      .appName("MySQLDemo")
      .getOrCreate()

    val jdbcDF = spark.read.format("jdbc")
      .option("url", "jdbc:mysql://localhost:3306/test")
      .option("dbtable", "tb_word_count")
      .option("user", "root")
      .option("password", "123456")
      .load()

    jdbcDF.show(true)

    spark.stop()
  }
}
